package com.mall.search.service.message;

import com.mall.pojo.SearchBean;
import com.mall.search.service.mappers.ItemsMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.solr.core.SolrTemplate;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;

/**
 * @author Administrator
 */
@Component
@Slf4j
public class ItemMessageConsumer {

    @Autowired
    ItemsMapper itemsMapper;

    @Autowired
    SolrTemplate solrTemplate;

    /**
     * 接收item队列消息并根据id更新索引库
     */
    @JmsListener(destination = "item-topic")
//    有返回值还可以继续往队列里面塞东西
//    @SendTo
    public void receive(String id){
        log.debug("添加商品索引id="+id);
        SearchBean searchBean = itemsMapper.selectById(Long.parseLong(id));
        solrTemplate.saveBean(searchBean);
        solrTemplate.commit();
    }

}
